package com.example.sign

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.SignBeanItem
import com.example.sign.databinding.ItemSignBinding

class SignAdapter : BaseQuickAdapter<SignBeanItem, BaseViewHolder>(R.layout.item_sign) {
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemSignBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: SignBeanItem) {
        val binding = DataBindingUtil.getBinding<ItemSignBinding>(helper.itemView)!!
        binding.bean = item
        var date = ""
        var time = ""
        if (item.morningCheckIn.isNotEmpty()){//上班卡
            val split = item.morningCheckIn.split(" ")
            date = split[0].replaceFirst("-", "年").replaceFirst("-", "月").plus("日")
            if (split.size>1){
                time = "上班${split[1]}"
            }
        }else{
            val split = item.afternoonCheckIn.split(" ")
            date = split[0].replaceFirst("-", "年").replaceFirst("-", "月").plus("日")
            if (split.size>1){
                time = "下班${split[1]}"
            }
        }
        binding.signDate.setText(date)
        binding.signTime.setText(time)

        binding.signStatus.apply {
            when(item.status){
                "正常"->{
                    setTextColor(context.getColor(R.color.green))
                    setBackgroundResource(R.drawable.shape_status)
                }

                "迟到"->{
                    setTextColor(context.getColor(R.color.orange))
                    setBackgroundResource(R.drawable.shape_weihu)
                }

                "早退"->{
                    setTextColor(context.getColor(R.color.redfont))
                    setBackgroundResource(R.drawable.shape_solid_red)
                }
            }
        }
    }
}